package com.zw.cloud.mybatis.plus.event;

import cn.hutool.core.lang.UUID;

import java.time.LocalDateTime;
import java.util.Date;

public class BaseEvent<T> {
    /**
     * 事件唯一ID
     */
    protected String id;
    /**
     * 事件发生时间
     */
    protected LocalDateTime occurredTime;
    /**
     * 事件类型 1: 内部事件  2:MQ  3:redis
     */
    protected int type = 1;

    /**
     * 事件源
     */
    protected String source = "默认";

    /**
     * 是否异步，默认是
     */
    protected boolean async = true;
    /**
     * 消息体
     */
    protected T message;

    public BaseEvent(String id, LocalDateTime occurredTime, int type, String source, T message) {
        this.id = id;
        this.occurredTime = occurredTime;
        this.type = type;
        this.source = source;
        this.message = message;
    }

    public BaseEvent(int type, String source, T message) {
        this.id = UUID.fastUUID().toString();
        this.occurredTime = LocalDateTime.now();
        this.type = type;
        this.source = source;
        this.message = message;
    }

    public BaseEvent(int type, T message) {
        this.id = UUID.fastUUID().toString();
        this.occurredTime = LocalDateTime.now();
        this.source = "默认";
        this.type = type;
        this.message = message;
    }

    public BaseEvent(int type, T message, boolean async) {
        this.id = UUID.fastUUID().toString();
        this.occurredTime = LocalDateTime.now();
        this.source = "默认";
        this.type = type;
        this.message = message;
        this.async = async;
    }

    public boolean isAsync() {
        return async;
    }

    public String getId() {
        return id;
    }

    public LocalDateTime getOccurredTime() {
        return occurredTime;
    }

    public int getType() {
        return type;
    }

    public String getSource() {
        return source;
    }

    public T getMessage() {
        return message;
    }
}
